﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Meraz.Core.Config
{
    public class TimelineElement : ConfigurationElement
    {
        private readonly DateTime LAST_WEEK = DateTime.Now.AddDays(-8);
        public TimelineElement() { }

        [ConfigurationProperty("baseUrl", DefaultValue="http://api.twitter.com/1/statuses/user_timeline.", IsRequired = true)]
        public string BaseUrl
        {
            get
            {
                return (string)this["baseUrl"];
            }
        }

        [ConfigurationProperty("count", DefaultValue = "10", IsRequired = true)]
        public int Count
        {
            get
            {
                return (int)this["count"];
            }
        }
        [ConfigurationProperty("format", DefaultValue = "", IsRequired = true)]
        public string Format
        {
            get
            {
                return (string)this["format"];
            }
        }
        [ConfigurationProperty("includeEntities", DefaultValue = "true", IsRequired = false)]
        public bool IncludeEntities
        {
            get
            {
                return (bool)this["includeEntities"];
            }
        }
        [ConfigurationProperty("trimUser", DefaultValue = "true", IsRequired = false)]
        public bool TrimUser
        {
            get
            {
                return (bool)this["trimUser"];
            }
        }

        public DateTime EndDate{get;set;}

        public string GetUrl(int page, string accountName)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(BaseUrl);
            sb.Append(Format);
            sb.Append("?");
            sb.AppendFormat("count={0}&", Count);
            if (IncludeEntities)
                sb.Append("include_entities=1&");
            else
                sb.Append("include_entities=0&");
            if (TrimUser)
                sb.Append("trim_user=1&");
            else
                sb.Append("trim_user=0&");
            sb.AppendFormat("screen_name={0}&", accountName);
            sb.AppendFormat("page={0}", page);
            return sb.ToString();

        }
    }
}